﻿using BarcodeDelay;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JTParcrelHelper.view
{
    public partial class FrmSpeedZC : Form
    {
        public FrmSpeedZC()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                StoParams.Instance.normalBeginExcuteTime = "";
                int parseMinNum = Convert.ToInt32(tbMin.Text);
                if(parseMinNum <= 0)
                {
                    MessageBox.Show("最小值1-4");
                    return;
                }

                int parseMiaxNum = Convert.ToInt32(tbMax.Text);
                if (parseMiaxNum <= 0|| parseMiaxNum>4)
                {
                    MessageBox.Show("最大值1-4");
                    return;
                }
                if(parseMiaxNum< parseMinNum)
                {
                    MessageBox.Show("最大值小于最小值不合法");
                    return;
                }

                StoParams.Instance.miniSpeed = parseMinNum;
                StoParams.Instance.maxSpeed = parseMiaxNum;

                DateTime dt = dtPicker.Value;

                if(dt< System.DateTime.Now.AddMinutes(-1))
                {
                    MessageBox.Show("时间选择不能小于当前时间");
                    return;
                }
               
                TimeSpan ts = System.DateTime.Now - dt;
                if(Math.Abs(ts.TotalMinutes) >2)
                {
                    StoParams.Instance.normalBeginExcuteTime = dt.ToString();
                }
                this.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("速度只能是数字");
            }

        }
    }
}
